package com.example.sxy_project;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import java.util.List;

class WeixinAdapter extends ArrayAdapter<Weixin> {
    private int resourceId;
    private static final String TAG = "WeixinAdapter";
    private List<Weixin> list;

    public WeixinAdapter(@NonNull Context context, int resource, @NonNull List<Weixin> objects) {
        super(context, resource, objects);
        resourceId = resource;
    }

    @NonNull
    @Override
    public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent)
    {
        Weixin weixin = getItem(position);
        View view = LayoutInflater.from(getContext()).inflate(resourceId,
                parent, false);
        ImageView fruitImage = view.findViewById(R.id.weixin_content_img);
        TextView fruitName = view.findViewById(R.id.weixin_content_txt1);
        TextView fruitNr = view.findViewById(R.id.weixin_content_txt2);

        fruitImage.setImageResource(weixin.getImageId());
        fruitName.setText(weixin.getName());
        fruitNr.setText(weixin.getNeirong());
        return view;
    }
}
